package com.yunti.springboot.controller;

import com.yunti.springboot.annotation.Log;
import com.yunti.springboot.annotation.Permission;
import com.yunti.springboot.service.UserService;
import com.yunti.springboot.vo.Result;
import com.yunti.springboot.vo.req.*;
import com.yunti.springboot.vo.res.UserConfigRes;
import com.yunti.springboot.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author Administrator
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;


    @PostMapping("/device_login")
    public Result device_login(@Valid @RequestBody UserLoginReq userLoginReq){
        return userService.device_login(userLoginReq);
    }

    @Log
    @PostMapping("/login")
    public Result login(@Valid @RequestBody UserLoginReq userLoginReq){
        return userService.login(userLoginReq);
    }

    @Log
    @PostMapping("/register")
    public Result register(@RequestBody RegisterParmReq registerParm){
        return userService.register(registerParm);
    }

    @PostMapping("/search")
    public Result<List<UserConfigRes>> getUserListPage(@RequestBody UserSearchReq userSearchReq){
        return userService.getUserListPage(userSearchReq);
    }

    @Log
    @GetMapping("/deleteUser")
    @Permission({"superAdmin"})
    public Result deleteUser(Integer id){
        return userService.deleteUser(id);
    }

    @Log
    @Permission({"superAdmin","userManage"})
    @GetMapping("/changSwitch")
    public Result changSwitch(@RequestParam("id") Integer id,@RequestParam("type") String type){
        return  userService.changSwitch(id,type);
    }

    @Log
    @Permission({"superAdmin","userManage"})
    @PostMapping("/updateUserById")
    public Result updateUserById(@RequestBody UpdateUserReq updateUserReq){
        return userService.updateUserById(updateUserReq);
    }

    @Log
    @PostMapping("/updatePassword")
    public Result updatePassword(@RequestBody UpdatePasswordReq updatePasswordReq){
        return userService.updatePassword(updatePasswordReq);
    }

    @PostMapping("/updateNickName")
    public Result updateNickName(@RequestBody UpdateNickNameReq updateNickNameReq){
        return userService.updateNickName(updateNickNameReq);
    }

    @PostMapping("/getChildrenUserList")
    public Result getChildrenUserList(@RequestBody UserSearchReq userSearchReq){
        return userService.getChildrenUserList(userSearchReq);
    }

    @PostMapping("/getLoginInfo")
    public Result getLoginInfo(){
        return userService.getLoginInfo();
    }

    @PostMapping("/checkLogin")
    public Result checkLogin(@RequestParam("token") String token){
        return userService.checkLogin(token);
    }
}
